package cn.anzhiyublog.staranimegallery.model.enums;

import lombok.Getter;

/**
 * 状态码
 *
 * @author 安知一只鱼
 */
@Getter
public enum StatusCode {
    SUCCESS(200, "成功"),
    NO_LOGIN(401, "未登录"),
    FORBIDDEN(403, "禁止访问"),
    NOT_FOUND(404, "资源不存在"),
    BAD_REQUEST(400, "错误的请求参数"),
    NOT_ACCEPTABLE(406, "请求格式不支持"),
    CONFLICT(409, "资源冲突"),
    INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
    ;

    private final int code;
    private final String message;

    StatusCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static StatusCode getEnumByCode(int code) {
        for (StatusCode statusCode : StatusCode.values()) {
            if (statusCode.getCode() == code) {
                return statusCode;
            }
        }
        return null;
    }
}
